package Models.dao;

import Models.enity.Commodit;
import Models.utils.DataSourceManager;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class CommoditDao {
    private QueryRunner runner = new QueryRunner(DataSourceManager.getDataSource());



    public List<Commodit> findAll(){
        String sql = "SELECT * FROM commodit";
        try {
            return runner.query(sql,new BeanListHandler<Commodit>(Commodit.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Commodit findById(String id){
        String sql = "SELECT * FROM commodit WHERE id=?";
        try {
            return runner.query(sql,new BeanHandler<Commodit>(Commodit.class),id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }








}
